package org.jeecg.modules.lab.syn;


import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.jeecg.common.cronJob.MyEnum;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
@Component
public class CopyFileJob  {

    @XxlJob("CopyFileJob")
    public ReturnT<String> execute(String params)  {
        String copyFilePath = MyEnum.copyFilePath;
        String realFilePath = MyEnum.realFilePath;
        File folder = new File(copyFilePath);
        //扫指定文件夹下的所有文件
        File[] scriptFiles = folder.listFiles();
        if (scriptFiles != null) {
            for (File scriptFile : scriptFiles) {
                // 复制到备份文件夹
                Path sourcePath = scriptFile.toPath();
                Path destPath = Paths.get(realFilePath, scriptFile.getName());
                try {
                    Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                scriptFile.delete();
            }
        }
        return ReturnT.SUCCESS;
    }
}
